package com.huluobo.kotlinim1907a.db

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import com.huluobo.kotlinim1907a.IMApplication
import org.jetbrains.anko.db.*

/**
 * Created by lc on 2022/1/19.
 */
class DatabaseHelper(ctx: Context = IMApplication.instance) : ManagedSQLiteOpenHelper(
    ctx, NAME, null, VERSION
) {
    companion object {
        const val NAME = "im.db"
        const val VERSION = 1
    }

    override fun onCreate(db: SQLiteDatabase?) {
        db?.createTable(
            ContactTable.NAME,//数据库表名
            true,//如果表不存在就给他创建一个
            ContactTable.ID to INTEGER + PRIMARY_KEY + AUTOINCREMENT,//表示id这一字段,int类型,主键,自动增长
            ContactTable.CONTACT to TEXT
        )
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        db?.dropTable(ContactTable.NAME, true)
        onCreate(db)
    }
}